#!/bin/bash
#GPL
#Sigmund Berglund, dec 2013

case $1 in ""|-h|--help)
	echo 'This box shows one ok-button, one icon, and textstring(s)
markup/span is valid

Usage :
  box_ok [--ok-label text] HEADING MSG-TYPE|ICON "textstring1" "textstring2" "..."

  HEADING  : title text
  MSG-TYPE : sets title/window icon
             can be: complete, info, error or warning
  ICON     : is a svg file. If path is not defined, /usr/share/pixmaps/puppy/ will be used

Example:
  box_ok "Title" info "read this message"
  box_ok --ok-label "Close" "Title" complete "Finished processing.."
  (3sec timeout): box_ok "heading" complete "text" &; XPID=$!; sleep 3; pkill -P $XPID
'
	exit ;;
esac

#======================================================

export TEXTDOMAIN=libstardust
export OUTPUT_CHARSET=UTF-8

OK_LABEL=$(gettext 'Ok')
for i in $@ ; do
	case $i in
		--ok-label)
			OK_LABEL="$2"
			shift 2
			;;
	esac
done

HEADING="$1"

case $2 in
	complete)
		ICON=/usr/share/pixmaps/puppy/dialog-complete.svg
		ICON_WM=gtk-yes
		FRAME="$(gettext 'Complete')"
		;;
	info)
		ICON=/usr/share/pixmaps/puppy/dialog-info.svg
		ICON_WM=gtk-info
		FRAME="$(gettext 'Info')"
		;;
	error)
		ICON=/usr/share/pixmaps/puppy/dialog-error.svg
		ICON_WM=gtk-no
		FRAME="$(gettext 'Error')"
		;;
	warning)
		ICON=/usr/share/pixmaps/puppy/dialog-warning.svg
		ICON_WM=gtk-warning
		FRAME="$(gettext 'Warning')"
		;;
	nb)
		ICON=/usr/share/pixmaps/puppy/nb.svg
		ICON_WM=gtk-no
		FRAME="$(gettext 'NB!')"
		;;
	*)
		ICON="$2"
		ICON_WM=gtk-about
		FRAME=" "
		;;
esac

S='
<window title="'$HEADING'" icon-name="'$ICON_WM'">
 <vbox space-expand="false" space-fill="false">
    <hbox height-request="10" space-expand="true" space-fill="true"><text><label>" "</label></text></hbox>
    <hbox>
      <vbox>
         <pixmap>
           <input file>'${ICON}'</input>
           <height>56</height>
           <width>56</width>
         </pixmap>
      </vbox>
      <vbox space-expand="false" space-fill="false">'
        [ "$3" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$3'"</label></text>'
        [ "$4" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$4'"</label></text>'
        [ "$5" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$5'"</label></text>'
        [ "$6" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$6'"</label></text>'
        [ "$7" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$7'"</label></text>'
        [ "$8" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$8'"</label></text>'
        [ "$9" ] && S=$S'<text xalign="0" use-markup="true"><label>"'$9'"</label></text>'
        [ "${10}" ] && S=$S'<text xalign="0" use-markup="true"><label>"'${10}'"</label></text>'
        [ "${11}" ] && S=$S'<text xalign="0" use-markup="true"><label>"'${11}'"</label></text>'
S=$S'
         <text xalign="0"><label>" "</label></text>
      </vbox>
    </hbox>
    <hbox space-expand="false" space-fill="false">
      <button>
         '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
         <label>" '${OK_LABEL}' "</label>
       </button>
    </hbox>
 </vbox>
</window>'

export box_ok="$S"
gtkdialog --center -p box_ok

### END ###
